public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
        System.out.println(optimizedFibonacciSum(5));
    }
    public static int optimizedFibonacciSum(int N) {
        if (N <= 0) return 0;
        if (N == 1) return 1;

        int a = 1, b = 1;//前两次的斐波那契数列
        for (int i = 2; i <= N + 1; i++) {
//            从2到N+1 正好是N次  可计算出第N+2次的数值
            int next = a + b;
            a = b;
            b = next;
        }
        return b - 1;//第(N+2)数值为前n次的和
    }
}